$(function(){	
    var navSelector = "ul#menu li";/** define the main navigation selector **/

    /** set up rounded corners for the selected elements **/
    $('.box-container').corners("5px bottom");
    $('.box h4').corners("5px top");
    $('ul.tab-menu li a').corners("5px top");
    $('textarea#wysiwyg').wysiwyg();
    $("div#sys-messages-container a, div#to-do-list ul li a").colorbox({
        fixedWidth:"50%", 
        transitionSpeed:"100", 
        inline:true, 
        href:"#sample-modal"
    }); /** jquery colorbox modal boxes for system
	 messages and to-do list - see colorbox help docs for help: http://colorpowered.com/colorbox/ **/
    $('#to-do').tabs();		 
    $("#calendar").datepicker();/** jquery ui calendar/date picker - see jquery ui docs for help: http://jqueryui.com/demos/ **/
    $("ul.list-links").accordion({
        active:-1
    });/** side menu accordion - see jquery ui docs for help:  http://jqueryui.com/demos/  **/
 
    jQuery(navSelector).find('a').css( {
        backgroundPosition: "0 0"
    } );
	
    jQuery(navSelector).hover(function(){/** build animated dropdown navigation **/
        jQuery(this).find('ul:first:hidden').css({
            visibility: "visible",
            display: "none"
        }).show("fast");
        jQuery(this).find('a').stop().animate({
            backgroundPosition:"(0 -40px)"
        },{
            duration:150
        });
        jQuery(this).find('a.top-level').addClass("blue");
    },function(){
        jQuery(this).find('ul:first').css({
            visibility: "hidden", 
            display:"none"
        });
        jQuery(this).find('a').stop().animate({
            backgroundPosition:"(0 0)"
        }, {
            duration:75
        });
        jQuery(this).find('a.top-level').removeClass("blue");
    });
    
    
    
    ///////////////////////////////////tann///////////
    $('#usersubmit').click(function() {
        $('#user-form').submit();
    });
    jQuery.validator.addMethod("password", function( value, element ) {
        var result = this.optional(element) || value.length >= 6;
        if (!result) {
            //element.value = "";
            var validator = this;
            setTimeout(function() {
                validator.blockFocusCleanup = true;
                element.focus();
                validator.blockFocusCleanup = false;
            }, 1);
        }
        return result;
    }, "Must be at least 6 characters long.");  
    $("#user-form").validate({
        messages: {
            //check input repeat password by checking id #repassword
            repassword: {
                required: "This field is required",
                equalTo: "Not same above password"
            },
            //check input repeat password by checking id #email
            email:{
                required: "This field is required",
                email: "Invalid email. Example(username@example.com)"
            }
        }
    });
    
    //validation login form 
    $("#login-form").validate({
        message: {
            username:{
                required: "This field is required"
            },
            password:{
                required: "This field is required" 
            }
        }
    });
    
    //validation project form
    $("#changePassword_form").validate();
    $("#project-form").validate();
    $('#projectsubmit').click(function() {
        $('#project-form').submit();
    });
    // button del-project in user-list-form
    $('.del-user').click(function() {
        $('#del-user').submit();
    });
    // button del-project in project-list-form
    $('.del-project').click(function() {
        $('#del-project').submit();
    //$('#del-project').submit();
    });
    $('#svn-submit').click(function() {
        //        $( "tbody" ).append( "<tr>" +
        //            "<td>" + $('select:#project').val() + "</td>" + 
        //            "<td>" + $('select:#user').text() + "</td>" + 
        //            "<td>" + $('select:#permission').text() + "</td>" +
        //            "</tr>" ); 
        $('#svn-form').submit();
    });
});